// Este programa desenha um chifrinho na nossa musa, Lena Söderberg


#include <cv.h>
#include <highgui.h>


#include <stdio.h>
#include <iostream> 
using namespace std;

 
int main (int argc, char **argv)
{
  // Janela
  const char *wnd = "Chifrinho";

  // Imagem
  IplImage *img;

  if (argc < 2) {
    printf ("Usage: %s <filename>/n", argv[0]);
    exit(1);
  }

  //
  // Lê arquivo de entrada. Imagens são convertidas para Grace Kelly.
  img = cvLoadImage (argv[1], CV_LOAD_IMAGE_COLOR);

  if (!img) {
    printf ("Couldn't load %s\n", argv[1]);
    exit(2);
  }

  // Desenha chifrinhos
  cvCircle(img, cvPoint(133, 133), 11, CV_RGB( 128, 10, 100 ), 3, CV_AA);
  cvCircle(img, cvPoint(166, 134), 11, CV_RGB( 128, 10, 100 ), 3, CV_AA);

  cvLine( img, cvPoint(171,113), cvPoint(170,101), CV_RGB( 255, 0, 0 ), 2, CV_AA, 0 );
  cvLine( img, cvPoint(170,101), cvPoint(162,109), CV_RGB( 255, 0, 0 ), 2, CV_AA, 0 );
  cvLine( img, cvPoint(147,110), cvPoint(145,97), CV_RGB( 255, 0, 0 ), 2, CV_AA, 0 );
  cvLine( img, cvPoint(145,97), cvPoint(137,108), CV_RGB( 255, 0, 0 ), 2, CV_AA, 0 );

  /*
    cvLine(img, cvPoint(149,168), cvPoint(144,166), CV_RGB( 0, 0, 0 ), 1, CV_AA, 0 );
  cvLine(img, cvPoint(144,166), cvPoint(134,171), CV_RGB( 0, 0, 0 ), 1, CV_AA, 0 );
  cvLine(img, cvPoint(134,171), cvPoint(128,163), CV_RGB( 0, 0, 0 ), 1, CV_AA, 0 );
  
  cvLine(img, cvPoint(153,168), cvPoint(156,166), CV_RGB( 0, 0, 0 ), 1, CV_AA, 0 );
  cvLine(img, cvPoint(156,166), cvPoint(162,170), CV_RGB( 0, 0, 0 ), 1, CV_AA, 0 );
  cvLine(img, cvPoint(162,170), cvPoint(166,162), CV_RGB( 0, 0, 0 ), 1, CV_AA, 0 );
  */

  CvPoint  curve1[]={149,168,144,166,134,171,128,163};
  CvPoint  curve2[]={153,168,156,166,162,170,166,162};

  CvPoint* curveArr[2]={curve1, curve2};
  int      nCurvePts[2]={4,4};
  int      nCurves=2;
  int      isCurveClosed=0;
  int      lineWidth=1;
  
  cvPolyLine(img,curveArr,nCurvePts,nCurves,isCurveClosed,cvScalar(0,0,0),lineWidth);

  cvLine(img, cvPoint(142,186), cvPoint(147,198), CV_RGB( 0, 0, 0 ), 2, CV_AA, 0 );
  cvLine(img, cvPoint(147,198), cvPoint(150,186), CV_RGB( 0, 0, 0 ), 2, CV_AA, 0 );
  cvLine(img, cvPoint(150,186), cvPoint(142,186), CV_RGB( 0, 0, 0 ), 2, CV_AA, 0 );

  CvFont font;
  cvInitFont(&font,CV_FONT_HERSHEY_SIMPLEX, 1.0, 1.0, 0, 2);
  cvPutText (img,"L.H.O.O.Q.", cvPoint(60,250), &font, CV_RGB(128,200,0));

  cvRectangle(img, cvPoint(25,25), cvPoint(225,225), CV_RGB(0,0,200), 2);


  // Parte GUI
  cvNamedWindow (wnd, 2);
  cvMoveWindow (wnd, 50 , 10);
  cvShowImage (wnd, img);
  cvWaitKey(0);


  cvReleaseImage (&img);
  return 0;  
}
